package com.richpath.animator;

import android.animation.Animator;
import android.animation.ValueAnimator;
import com.richpath.RichPath;
import java.util.ArrayList;
import java.util.List;


public class RichPathAnimator extends RichAnimator<RichPathAnimator> {

    private List<AnimationBuilder> animationBuilders = new ArrayList<>();

    private RichPathAnimator() {
    }

    AnimationBuilder addAnimationBuilder(RichPath... paths) {
        AnimationBuilder animationBuilder = new AnimationBuilder(this, paths);
        animationBuilders.add(animationBuilder);
        return animationBuilder;
    }

    AnimationBuilder thenAnimate(RichPath... paths) {
        RichPathAnimator nextRichPathAnimator = new RichPathAnimator();
        this.next = nextRichPathAnimator;
        nextRichPathAnimator.prev = this;
        return nextRichPathAnimator.addAnimationBuilder(paths);
    }

    @Override
    public List<Animator> createAnimatorList() {
        List<Animator> animators = new ArrayList<>();
        for (AnimationBuilder animationBuilder : animationBuilders) {
            List<ValueAnimator> animatorList = animationBuilder.getAnimators();
            animators.addAll(animatorList);
            if (repeatMode != RepeatMode.UNSET) {
                animationBuilder.repeatMode(repeatMode);
            }

            if (repeatCount != -2) {
                animationBuilder.repeatCount(repeatCount);
            }
        }
        return animators;
    }

    public static AnimationBuilder animate(RichPath... paths) {
        RichPathAnimator viewAnimator = new RichPathAnimator();
        return viewAnimator.addAnimationBuilder(paths);
    }
}